package com.kaiwukj.android.ufamily.mvp.model;

import com.blankj.utilcode.util.GsonUtils;
import com.kaiwukj.android.mcas.integration.IRepositoryManager;
import com.kaiwukj.android.mcas.mvp.BaseModel;
import com.kaiwukj.android.ufamily.mvp.http.api.service.DynamicService;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.ChatSearchGroupResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.ChatSearchPersonResult;
import com.kaiwukj.android.ufamily.mvp.http.utils.RxUtils;
import com.kaiwukj.android.ufamily.mvp.ui.page.message.MessageContract;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.Observable;

public class MessageModel extends BaseModel implements MessageContract.Model {

    @Inject
    public MessageModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public Observable<List<ChatSearchPersonResult>> searchChatPersonResult(String keyword) {
        return mRepositoryManager.obtainRetrofitService(DynamicService.class)
                .fetchSearchPersonResult(keyword)
                .compose(RxUtils.handleResult());
    }

    @Override
    public Observable<List<ChatSearchGroupResult>> searchChatGroupResult(String keyword) {
        return mRepositoryManager.obtainRetrofitService(DynamicService.class)
                .fetchSearchGroupResult(keyword)
                .compose(RxUtils.handleResult());
    }

    @Override
    public Observable<Integer> attention(int userId) {
        Map<String, Object> params = new HashMap<>();
        params.put("beConcernId", userId);
        return mRepositoryManager.obtainRetrofitService(DynamicService.class)
                .attention(getRequestBody(GsonUtils.toJson(params)))
                .compose(RxUtils.handleCode());
    }

    @Override
    public Observable<Integer> cancelAttention(int userId) {
        return mRepositoryManager.obtainRetrofitService(DynamicService.class)
                .cancelAttention(userId)
                .compose(RxUtils.handleCode());
    }
}
